import cv2
import mss
import numpy as np
from time import time
from random import randint
from paddleocr import PaddleOCR

def test1():
    m = mss.mss()
    img1 = m.grab((randint(1,50),randint(1,50),100,100))
    limg = np.array(img1)
    gray = cv2.cvtColor(limg, cv2.COLOR_RGB2GRAY)
    _, binary = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)
    cv2.imwrite('test.jpg',binary)
    
def test2():
    gray = cv2.imread('shot_image/001122_1669455967.1475656.png',cv2.IMREAD_GRAYSCALE)
    _, binary = cv2.threshold(gray, 130, 255, cv2.THRESH_BINARY)
    # cv2.imshow('kkk',binary)
    # cv2.waitKey(0)
    # exit(0)
    cv2.imwrite('test.jpg',binary)
    ocr = PaddleOCR(use_angle_cls=False, lang='ch', show_log='INFO')
    result = ocr.ocr('shot_image/20221128101017.png', cls=False, det=False)
    print(result)
    # for res in result:
    #     print(res[1][0])
    
def test3():
    bimg = cv2.imread('shot_image/001122_1669603157.8923783.png')
    limg = np.split(bimg,23)
    del limg[0]
    for i in range(2,12):
        del limg[i]
    ocr = PaddleOCR(use_angle_cls=False, lang='ch', show_log='INFO')
    result = ocr.ocr(limg, cls=False, det=False)
    data = []
    for res in result:
        if res[0][-1]=='万':
            code = float(res[0][:-1])*10000
            data.append(str(code))
        elif res[0][-1]=='亿':
            code = float(res[0][:-1])*100000000
            data.append(str(code))
        else:
            data.append(res[0])
    print(','.join(data))
    
test3()